<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
  defined('_JEXEC') or die('Retricted Access');
  global $option, $jbconfig;
  $item = $this->item;
  
  $editor =& JFactory::getEditor();
  $username = JRequest::getVar('username');
  $user_id = JRequest::getInt('userid');
  if ($user_id)
  $item->user_id = $user_id;
  $user = JFactory::getUser($item->user_id);
  if ($user)
  	$name = $user->name;
  else 
  	$name = '';
?>

<script language="javascript" type="text/javascript">
siteurl = '<?php echo JURI::base();  ?>';

function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if (pressbutton == 'save'||pressbutton == 'apply') {
		if ( form.title.value == "" ) {
			alert("<?php echo JText::_( 'Transaction must have title', true ); ?>");
			form.title.focus();
			return;
		}
		var numericExpression = /^[0-9]+$/;
		var numericExpression1 = /^[0-9]+\.[0-9]{1,2}$/;
		$submitform = 0;
		
		var product_id = form.product_id.value;
		if ((product_id == ""))
		{
			alert("<?php echo JText::_( 'Product ID could not be empty', true ); ?>");
			form.product_id.focus();
			return;
		}
		else 
		{
			if(product_id !="")
			{
				if(product_id.match(numericExpression)||product_id.match(numericExpression1))
				{
					$submitform =1;
				}
				else
				{
					alert("<?php echo JText::_( 'Product ID must be numeric', true ); ?>");
					form.product_id.focus();
					return;
				}
			}
			
		}
		
		var user_id = form.user_id.value;
		if ((user_id == ""))
		{
			alert("<?php echo JText::_( 'Customer ID could not be empty', true ); ?>");
			form.user_id.focus();
			return;
		}
		else 
		{
			if ($('user_error').value=='1')
			{
				alert('<?php echo JText::_('This user is not exist'); ?>');
				return;
			}
			if(user_id !="")
			{
				if(user_id.match(numericExpression)||user_id.match(numericExpression1))
				{
					$submitform =1;
				}
				else
				{
					alert("<?php echo JText::_( 'Customer ID must be numeric', true ); ?>");
					form.user_id.focus();
					return;
				}
			}
			
		}
		
		var amount =document.getElementById('amount');
		amount = amount.value;
		if ((amount == ""))
		{
			alert("<?php echo JText::_( 'Transaction amount could not be empty', true ); ?>");
			form.amount.focus();
			return;
		}
		else 
		{
			if(amount !="")
			{
				if(amount.match(numericExpression)||amount.match(numericExpression1))
				{
					$submitform =1;
				}
				else
				{
					alert("<?php echo JText::_( 'Transaction amount must be numeric', true ); ?>");
					form.amount.focus();
					return;
				}
			}
			
		}
		if($submitform ==1)
		{
			submitform(pressbutton);
			return;
		}	
	}
	else {
		<?php
		echo $editor->save( 'reason' ) ; 
		?>
		submitform(pressbutton);
	}
}

function submitform(pressbutton)
{
	form = document.adminForm;
	form.task.value = pressbutton;
	form.submit();
}

function change_status()
{
	form = document.adminForm;
	if (form.check_status.checked)
		form.completed.value = 1;
	else
		form.completed.value = 0;
	
}


function assign_user(user_id)
{
	document.getElementById('user_id').value = user_id;	
	document.getElementById('user_id').focus();	
	document.getElementById('sbox-window').close();
}

function assign_product(product_id,amount,product_type,value_type)
{
	document.getElementById('product_id').value = product_id;	
	document.getElementById('product_id').focus();
	document.getElementById('amount').value = amount;
	document.getElementById('product_type').value = product_type;
	document.getElementById('value_type').value = value_type;
	document.getElementById('sbox-window').close();
}

function validate_userid(){
	var name_userid = $("check_username");
	var userid = $('user_id');
	
	if(userid.value=='')	{
		name_userid.innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;"><?php echo JText::_('Please enter Custommer ID'); ?></span>';
		return false;
	}
	else{
		$('check_username').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/loading.gif" alt="" title="" />';
		var url = 'index.php?option=com_jajobboard&view=jatransactions&task=check_user&user_id='+escape(userid.value);
		new Ajax(url, {method:'get', onComplete:updateValidate_userid}).request();	
	}
}

function updateValidate_userid(text){
	if(text=='Yeah')
	{
		$('check_username').innerHTML = '<img title="" alt="" src="' + siteurl + 'components/com_jajobboard/images/ok.png"/>';
		$('user_error').value = 0;
	}
	else
	{
		$('check_username').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;">' + text + '</span>';
		$('user_error').value = 1;
	}

}
//function validate_productid(){
//	var name_productid = $("check_product");
//	var productid = $('product_id');
//	
//	if(productid.value=='')	{
//		name_productid.innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;"><?php echo JText::_('Please enter Product ID'); ?></span>';
//		return false;
//	}
//	else{
//		$('check_product').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/loading.gif" alt="" title="" />';
//		var url = 'index.php?option=com_jajobboard&view=jatransactions&task=check_product&product_id='+escape(productid.value + '&product_type=' + $('product_type').value);
//		new Ajax(url, {method:'get', onComplete:updateValidate_productid}).request();	
//	}
//}
//
//function updateValidate_productid(text){
//	if(text=='Yeah')
//	{
//		$('check_product').innerHTML = '<img title="" alt="" src="' + siteurl + 'components/com_jajobboard/images/ok.png"/>';
//		
//	}
//	else
//		$('check_product').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/not.png" alt="" title="" /><span style="font-weight: bold;color: red;">' + text + '</span>';
//
//}
//function show_url_product_list()
//{
//	alert('index.php?option=com_jajobboard&view=jatransactions&layout=element_product&tmpl=component&product_type=' + $('product_type').value);
//	return 'index.php?option=com_jajobboard&view=jatransactions&layout=element_product&tmpl=component&product_type=' + $('product_type').value;
//}

function change_product_type(value){
	var s_productid = $('wait_load_product');
	
	$('wait_load_product').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/loading.gif" alt="" title="" />';
	var url = 'index.php?option=com_jajobboard&view=jatransactions&task=show_product_object_list&product_type='+ value;
	new Ajax(url, {method:'get', onComplete:updateValidate_productid}).request();	
	
}

function updateValidate_productid(text){
	$('wait_load_product').innerHTML ='';
	$('s_productid').innerHTML = text;

}

function change_product_id(value){
	var change_productid = $('change_productid');
	if (!value)
	{
		$('amount').value = '';
		$('value_type').value = '';
		$('value').value ='';
		return;
	}
	$('change_productid').innerHTML = '<img src="' + siteurl + 'components/com_jajobboard/images/loading.gif" alt="" title="" />';
	var url = 'index.php?option=com_jajobboard&view=jatransactions&task=show_product_info&product_id='+ value + '&product_type='+$("product_type").value;
	new Ajax(url, {method:'get', onComplete:update_productid}).request();	
	
}

function update_productid(text){
	$('change_productid').innerHTML = '&nbsp';
	$('amount').value = text.substring(0,text.indexOf('_'));
	temp = text.substring(text.indexOf('_')+1,text.length);
	$('value_type').value = temp.substring(0,temp.indexOf('_'));
	$('value').value = temp.substring(temp.indexOf('_')+1,text.length);
}

</script>
<form name="adminForm" action="index.php" method="post" enctype="multipart/form-data">

	<table width="100%">
	<?php 
	$task = JRequest::getVar('task');
	if ($task=='trans_viewbyuser')
	{
	?>
		<tr>
			<td width="80%" valign="top">
				<div style="width:100%;">
					<?php echo $this->menu();?>
				</div>
			</td>
		</tr>
	<?php
	}
	?>	
	<tr>
	
		<td width="80%" valign="top" align="left">
		
		    <div style="width:100%;">
				<fieldset class="adminform">
					<legend><?php echo JText::_( 'Transaction details' ); ?></legend>
						<table class="admintable">
						<tr>
							<td valign="top" class="key">
								<label for="user_id">
									<?php echo JText::_( 'Customer' ); ?>: <font color="Red">*</font>	
								</label>
								<br />
								<small><?php echo JText::_('Enter user\'s ID');?></small>
							</td>
							<td id="td-user-id">
								<?php if (!$item->id) {?>
								<input id="user_id" type="text" size="10" name="user_id" value="<?php echo $item->user_id ?>" onblur="validate_userid(this.value);"/>
								<a class="modal" rel="{handler: 'iframe', size: {x: 650, y: 375}}" href="index.php?option=com_jajobboard&view=jatransactions&layout=element_user&tmpl=component" title="Select an User">(<?php echo JText::_('Select'); ?>)</a>
								<span id="check_username"> &nbsp;</span>
								<?php } else { ?>
								<label><?php echo $name.' ('.$item->user_id.')'; ?></label>
								<input type="hidden" name="user_id" id="user_id" value="<?php echo $item->user_id; ?>" />
								<?php } ?>
							</td>
						</tr>
						<tr>
							<td width="120" class="key">
								<?php echo JText::_( 'Completed' ); ?>:
							</td>
							<td>
								
							<input type="checkbox" name="check_status" value="" <?php echo ($item->completed=='1')?'checked':''; ?>" onclick="change_status()" />		
							</td>
						</tr>
								
						<tr>
							<td class="key">
								<label for="product_type">
									<?php echo JText::_( 'Product type' ); ?>:	
								</label>
							</td>
							<td>
		       				<?php 
		       					echo $this->product_type;				
		       				?>	
		       				<span id="wait_load_product">&nbsp;</span>
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="product_id" width="100">
									<?php echo JText::_( 'Product' ).' (ID)'; ?>: <font color="Red">*</font>
								</label>
								
							</td>
							<td colspan="2">
<!--								<input type="text" size="10" id="product_id" name="product_id" value="<?php echo $item->product_id; ?>"  onblur="validate_productid(this.value);" />-->
<!--								<a class="modal" rel="{handler: 'iframe', size: {x: 650, y: 375}}" href="show_url_product_list()" title="Select product">(<?php echo JText::_('Select'); ?>)</a>-->
<!--								<span id="check_product"> &nbsp;</span>-->
								<span id="s_productid"><?php echo $this->objproductid; ?></span><span id='change_productid'>&nbsp;</span>
		       					
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="amount">
									<?php 
										if ($item->id)
											$currency_code = $item->currency_code;
										else 
											$currency_code = getCurrencySymbol();
										echo JText::_('Amount' ).' ('.$currency_code.')'; 
									?>
								</label>:
								 <font color="Red">*</font>
							</td>
							<td>
								<input class="text_area" type="text" name="amount" id="amount" value="<?php echo $item->amount; ?>" size="10" maxlength="50" />
								
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="txn_id" width="100">
									<?php echo JText::_( 'Receipt ID' ); ?>:					
								</label>
								
							</td>
							<td colspan="2">
								<input type="text" size="30" name="txn_id" value="<?php echo $item->txn_id; ?>" />
							</td>
						</tr>						
						<tr>
							<td class="key">
								<label for="created_date">
									<?php echo JText::_( 'Created date' ); ?>:							
								</label>												
							</td>
							<td>
								<?php 
									if (!$item->id) 
										$item->created_date = date('Y-m-d H:i:s'); 
									
									echo JHTML::_('calendar', $item->created_date, 'created_date', 'created_date', '%Y-%m-%d %H:%M:%S', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?>						
							</td>
						</tr>
						
						
								
						<tr>
							<td class="key">
								<label for="payment_method">
									<?php echo JText::_( 'Payment Method' ); ?>:
								</label>						
							</td>
							<td valign="top" colspan="3">
								<?php
									echo $this->paysys;
								?>
							</td>
						</tr>						
						<?php if ($item->id) {?>
						<tr>
							<td class="key">
								<label for="processed_date">
									<?php echo JText::_( 'Processed date' ); ?>:							
								</label>												
							</td>
							<td>
								<?php  echo JHTML::_('calendar', $item->processed_date, 'processed_date', 'processed_date', '%Y-%m-%d %H:%M:%S', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?>						
							</td>
						</tr>		
						
						<!--<tr>
							<td class="key">
								<label for="ip">
									<?php echo JText::_( 'IP Address' ); ?>:
								</label>						
							</td>
							<td valign="top" colspan="3">
								<input type="text" size="50" name="ip" value="<?php echo $item->ip; ?>" />
							</td>
						</tr>	
						--><?php } ?>
						<!--<tr>
							<td class="key">
								<label for="reason">
									<?php echo JText::_( 'Reason' ); ?>:
								</label>						
							</td>
							<td valign="top" colspan="3">
								<input type="text" name="reason" size="90" id="reason" value="<?php echo $item->reason; ?>" />
							</td>
						</tr>	
						--><tr>
							<td class="key">
								<label for="detail">
									<?php echo JText::_( 'Detail' ); ?>:
								</label>						
							</td>
							<td valign="top" colspan="3">
								<?php
									echo $editor->display( 'detail',  htmlspecialchars($item->detail, ENT_QUOTES), '300', '50', '60', '20', array('pagebreak', 'readmore') ) ;									
								?>
							</td>
						</tr>												
					</table>
				</fieldset>
			
			</div>
			
		</td>
	</tr>
			
	</table>
	<input type="hidden" name="user_error" id="user_error" value="" />
	<input type="hidden" name="currency_code" value="<?php echo $item->currency_code?$item->currency_code:getCurrency(); ?>" />
	<input type="hidden" name="completed" value="<?php echo $item->completed; ?>" />
	<input type="hidden" name="id" value="<?php echo $item->id; ?>">
	<input type="hidden" name="reference" value="<?php echo $item->reference; ?>">
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="view" value="jatransactions" />
	<!--<input type="hidden" name="oldtitle" value="<?php echo $row->title ; ?>" />-->
	<input type="hidden" name="cid" value="<?php echo $item->id; ?>" />
	<input type="hidden" name="boxchecked" value="1" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="pre_task" value="<?php echo $task; ?>" />
	<input type="hidden" name="userid" value="<?php echo $user_id; ?>" />
	<input type="hidden" id="value_type" name="value_type" value="<?php echo $item->value_type; ?>" />
	<input type="hidden" id="value" name="value" value="<?php echo $item->value; ?>" />
</form>